<?php
session_start();
require_once 'database.php';

// 获取ID
if (!isset($_GET['id'])) {
    header('Location: index.php');
    exit;
}

$trainingId = $_GET['id'];

// 检查是否已登录
if (isset($_SESSION['username']) && $_SESSION['username'] == 'admin') {
    // 删除
    try {
        $stmt = $pdo->prepare('DELETE FROM trainings WHERE id = ?');
        $stmt->execute([$trainingId]);
    } catch (PDOException $e) {
        die('删除失败: ' . $e->getMessage());
    }
}

// 重定向回用户管理页面
header('Location: index.php');
exit;
?>